<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib uri="/struts-tags" prefix="s"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>


<link href="${pageContext.request.contextPath}/css/sub_manager.css"
	rel="stylesheet" type="text/css" />

<script src="${pageContext.request.contextPath}/js/sub_manager.js"></script>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>测试题管理页面</title>
</head>
<body onload="getAllSubListFunctono();">

	<script defer="defer" type="text/javascript">
		function clickItme(item) {

			var val = $(item).attr('uuid');

			var url = "${pageContext.request.contextPath}/index_subDetaileManager.action?time="
					+ new Date().getTime();

			delCookie("uuid");
			document.cookie = "uuid=" + val;

			window.location = url;

		}
		function delCookie(name) {
			var exp = new Date();
			exp.setTime(exp.getTime() - 1);
			var cval = getCookie(name);
			if (cval != null)
				document.cookie = name + "=" + cval + ";expires="
						+ exp.toGMTString();
		}
		function getCookie(name) {
			var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
			if (arr = document.cookie.match(reg))
				return unescape(arr[2]);
			else
				return null;
		}
		function getAllSubListFunctono() {
			<s:if test="#session.userModel == null">
			</s:if>
			<s:else>
			var url = "${pageContext.request.contextPath}/sub_getAllCommonSubList.action?time="
					+ new Date().getTime();

			var loadViwe = showLoading(" 正在加载 中  ... ... ",function(){
				
			});
			$
					.get(
							url,
							{

							},
							function(data, textStatus) {
								if (textStatus == "success") {
									loadViwe.fadeOut("fast", function() {
										loadViwe.remove();
									});
									var responseObj = data;
									var code = responseObj.code;
									var message = responseObj.message;
									if (code == "1000") {
										var list = responseObj.content;
										var $tables = $('#table_all_sub_list');

										for ( var i = 0; i < list.length; i++) {
											var obj = list[i];
											var $tr = $("<tr>"
													+ "<th  class='table_first_th' >"
													+ (i + 1)
													+ "</th>"
													+ "<td class='table_first_th'>"
													+ obj.uSubName
													+ "</td>"
													+ "<td class='table_first_th'>"
													+ obj.formatTime
													+ "</td>"
													+ "<td  class='table_first_th' onclick='clickItme(this)' uuid= "
													+ obj.uSubUid
													+ " >查看详情</td>" + "</tr>");
											$tables.append($tr);
										}

									} else {

									}

								} else {
									alert("加载失败");
								}
							}, "json");

			</s:else>
		}
	</script>

	<div class="main">
		<%@ include file="header.jsp"%>

		<s:if test="#session.userModel == null">
			<div class="div_user_no_login_main">
				<div onclick="toLoginPage()">请登录</div>
			</div>
		</s:if>




		<s:else>
			<div class="div_login_no_user_main">

				<table id="table_all_sub_list" cellpadding="2" cellspacing="0">
					<tr>

						<th class='table_first_th'>序号</th>
						<th class='table_first_th'>题名称</th>
						<th class='table_first_th'>时间</th>
						<th class='table_first_th'>详情</th>

					</tr>
				</table>
			</div>
			<div class="div_add_sub">
				<div id="div_add_sub" onclick="addSubFunction()">添加试题</div>
				<div isShow="no" id="div_sub_content">

					<div class="div_sub_content">
						<div class="div_sub_content_title">标题</div>
						<div class="div_sub_content_des">
							<textarea class="text_sub_content_des" rows="10" cols="10"
								id="subTitl"></textarea>
						</div>
						<div class="div_sub_content_title">题记</div>
						<div class="div_sub_content_des">
							<textarea class="text_sub_content_des" rows="10" cols="10"
								id="subSign"></textarea>
						</div>
						<div class="div_add_sub_commit">
							<div id="div_add_sub_commit" onclick="commidAddSubFunction()">提交试题</div>
						</div>
					</div>

				</div>
			</div>


		</s:else>
	</div>
	<script type="text/javascript">
		function addSubFunction() {

			var $sub_contnt = $('#div_sub_content');

			var isShow = $sub_contnt.attr("isShow");

			if (isShow == "no") {
				$sub_contnt.attr("isShow", "yes");
				$("#div_add_sub").html("取消添加");
				$sub_contnt.css({
					"display" : "block"
				});
			} else {
				$sub_contnt.attr("isShow", "no");
				$("#div_add_sub").html("添加试题");
				$sub_contnt.css({
					"display" : "none"
				});
			}

		}
	</script>

	<script type="text/javascript">
		function commidAddSubFunction() {
			var url = "${pageContext.request.contextPath}/sub_addCommonSub.action?time="
					+ new Date().getTime();

			$
					.post(
							url,
							{
								subTitl : encodeURI($("#subTitl").val()),
								subSign : encodeURI($("#subSign").val())
							},
							function(data, textStatus) {
								if (textStatus == "success") {
									console.log("The add sub is : " + data);
									alert("添加成功");
									var furl = "${pageContext.request.contextPath }/index_subManagerPage.action?time="
											+ new Date().getTime();

									window.location = furl;
								} else {
									alert("添加失败");
								}
							});
		}
	</script>



</body>
</html>